# -*- coding: utf-8 -*-
"""
其他项目的示例参考，用于dev环境的全局配置
"""
import os, sys
from settings import APP_ID
from settings import LOG_CLASS, LOG_LEVEL, LOGGING_DIR
from settings import IS_USE_CELERY, RUN_MODE, INSTALLED_APPS
# 本人机器开发配置


# ===============================================================================
# CELERY 配置
# ===============================================================================
BROKER_URL_DEV = 'amqp://app-job:app-job@197.68.2.26:9007/test_app-job'

if IS_USE_CELERY and RUN_MODE == 'DEVELOP':
    try:
        import djcelery

        INSTALLED_APPS += (
            'djcelery',  # djcelery
        )
        djcelery.setup_loader()
        CELERY_ENABLE_UTC = False
        CELERYBEAT_SCHEDULER = "djcelery.schedulers.DatabaseScheduler"
        if "celery" in sys.argv:
            DEBUG = False
        # celery 的消息队列（RabbitMQ）信息
        BROKER_URL = os.environ.get('BK_BROKER_URL', BROKER_URL_DEV)
        if RUN_MODE == 'DEVELOP':
            from celery.signals import worker_process_init


            @worker_process_init.connect
            def configure_workers(*args, **kwargs):
                import django
                django.setup()
    except:
        pass


DEFAULT_BK_BIZ_ID = 18  # 4:应用发布测试业务ID

ZABBIX_APP_URL = 'http://197.68.2.50/api_jsonrpc.php'
ZABBIX_APP_USER = 'Admin'
ZABBIX_APP_PASS = 'zabbix'

# ===============================================================================
# 数据库设置, 测试环境数据库设置
# ===============================================================================
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',  # 默认用mysql
        'NAME': 'app-publish_v2_dev',                    # 数据库名 (默认与APP_ID相同)
        'USER': 'hatmax-asm',                            # 你的数据库user
        'PASSWORD': 'hatmax-asm',                        # 你的数据库password
        'HOST': '197.68.2.26',                           # 数据库HOST
        'PORT': '3306',                        # 默认3306

    },
    'hatmax-asm': {
        'ENGINE': 'django.db.backends.mysql',  # 默认用mysql
        'NAME': 'hatmax-asm_dev',  # 数据库名 (默认与APP_ID相同)
        'USER': 'hatmax-asm',  # 你的数据库user
        'PASSWORD': 'hatmax-asm',  # 你的数据库password
        'HOST': '197.68.2.26',  # 数据库HOST
        'PORT': '3306',  # 默认3306
        'OPTIONS': {                            # 取消foreign_key检查,解决新建foreign_key列报错
            'init_command': 'SET foreign_key_checks = 0;',
        },
    },
}




LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s [%(asctime)s] %(pathname)s %(lineno)d %(funcName)s %(process)d %(thread)d \n \t %(message)s \n',
            # noqa
            'datefmt': '%Y-%m-%d %H:%M:%S'
        },
        'simple': {
            'format': '%(levelname)s %(message)s \n'
        },
        'develop': {
            'format': '%(levelname)s|%(asctime)s|%(filename)s|%(lineno)d|%(funcName)s|%(message)s',
            # noqa
            'datefmt': '%Y%m%d,%H%M%S'
        },
        'develop_simple': {
            'format': '%(levelname)s [%(asctime)s] %(message)s',
            # noqa
            'datefmt': '%Y-%m-%d %H:%M:%S'
        },
    },
    'handlers': {
        'null': {
            'level': 'DEBUG',
            'class': 'django.utils.log.NullHandler',
        },
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'console_simple': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'develop_simple'
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'develop'
        },
        'root': {
            'class': LOG_CLASS,
            'formatter': 'verbose',
            'filename': os.path.join(LOGGING_DIR, '%s.log' % APP_ID),
            'maxBytes': 1024 * 1024 * 10,
            'backupCount': 5
        },
        'component': {
            'class': LOG_CLASS,
            'formatter': 'verbose',
            'filename': os.path.join(LOGGING_DIR, 'component.log'),
            'maxBytes': 1024 * 1024 * 10,
            'backupCount': 5
        },
        'wb_mysql': {
            'class': LOG_CLASS,
            'formatter': 'verbose',
            'filename': os.path.join(LOGGING_DIR, 'wb_mysql.log'),
            'maxBytes': 1024 * 1024 * 4,
            'backupCount': 5
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'django.request': {
            'handlers': ['console'],
            'level': 'ERROR',
            'propagate': True,
        },
        # the root logger ,用于整个project的logger
        'root': {
            'handlers': ['console'],
            'level': LOG_LEVEL,
            'propagate': True,
        },
        # 组件调用日志
        'component': {
            'handlers': ['console'],
            'level': 'WARN',
            'propagate': True,
        },
        # sql显示...
        'django.db.backends': {
            'handlers': ['console'],
            'level': 'DEBUG',
            'propagate': False,  # 不传给根日志
        },
    }
}